package com.adf.admin.controller;

import com.adf.admin.entity.PageResult;
import com.adf.admin.service.IRoleQueryService;
import com.adf.admin.service.IUserRoleQueryService;
import com.adf.admin.vo.RoleQueryVO;
import com.adf.admin.vo.UserRoleQueryVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sam.zheng
 * @since 2025-10-30 18:21:23
 */
@RestController
@RequestMapping("/admin/role")
public class RoleController {

    @Autowired
    IRoleQueryService roleQueryService;

    @Autowired
    private IUserRoleQueryService userRoleQueryService;

    @GetMapping("dotest")
    public String doTest(){

        System.out.println("执行doTest方法");

        int pageIndex =1;
        if(pageIndex <= 0){
            pageIndex = 1;
        }

        int pageSize = 2;
        if(pageSize <= 0){
            pageSize = 20;
        }

        StringBuilder sbInfo = new StringBuilder();


        RoleQueryVO query = new RoleQueryVO();
        query.setName("管理员");

        Page<RoleQueryVO> page = new Page<>();
        page.setCurrent(1);
        page.setSize(10);

        IPage<RoleQueryVO> queryPage = roleQueryService.getPageList(page,query);


        System.out.println("queryPage" + queryPage.getPages());

        List<RoleQueryVO> lstInfo = queryPage.getRecords();


        for(RoleQueryVO entity : lstInfo){
            sbInfo.append(entity.getName());
        }


        Page<UserRoleQueryVO> userRoleQueryVOPage = new Page<>();
        userRoleQueryVOPage.setCurrent(1);
        userRoleQueryVOPage.setSize(100);

        UserRoleQueryVO userRoleQueryVOQuery = new UserRoleQueryVO();
        userRoleQueryVOQuery.setRoleName("平");

        IPage<UserRoleQueryVO> queryVOIPage = userRoleQueryService.getPageList(userRoleQueryVOPage,userRoleQueryVOQuery);

        sbInfo.append("----------");
        //sbInfo.setLength(0);
        List<UserRoleQueryVO> lstUserRoleQueryVo = queryVOIPage.getRecords();
        for(UserRoleQueryVO userRoleQueryVO : lstUserRoleQueryVo){

            sbInfo.append(userRoleQueryVO.getRoleName() + "," + userRoleQueryVO.getUserName());
        }

        /*
        RoleQueryVO query = new RoleQueryVO();
        PageResult<RoleQueryVO> page = roleQueryService.getPageList(pageIndex,pageSize,query);

        List<RoleQueryVO> lstInfo = page.getRecords();


        for(RoleQueryVO entity : lstInfo){
            sbInfo.append(entity.getName());
        }

         */

        return sbInfo.toString();
    }
}
